local lsp_jizha = fk.CreateSkill {
    name = "lsp_jizha",
}

Fk:loadTranslationTable {
    ["lsp_jizha"] = "讥诈",
    [":lsp_jizha"] = "出牌阶段限一次，你可以将一张手牌置于武将牌上并声明一种牌名，令一名其他角色猜测你声明的牌与武将牌上的牌是否一致。<br>" ..
        "若其猜错，你将“讥诈”当做你声明的牌对其使用，若你声明的牌不为装备牌，结算结束后，你可以视为对其使用同名牌；若其猜对，其对你使用“讥诈”牌(无懈可击、闪和借刀杀人除外)。",

    ["$lsp_jizha"] = "讥诈",
    ["#lsp_jizha-use"] = "讥诈：你可以再次视为 %dest 对使用【%arg】。",
}
local U = require "packages/utility/utility"
lsp_jizha:addEffect("active", {
    anim_type = "support",
    card_num = 1,
    target_num = 1,
    can_use = function(self, player)
        return player:usedSkillTimes(lsp_jizha.name, Player.HistoryPhase) == 0 and player:getHandcardNum() > 0
    end,
    card_filter = function(self, player, to_select, selected)
        return #selected == 0 and Fk:getCardById(to_select).trueName ~= "jink" and
            Fk:getCardById(to_select).trueName ~= "nullification" and
            table.contains(player.player_cards[Player.Hand], to_select)
    end,
    target_filter = function(self, player, to_select, selected)
        return #selected == 0 and to_select ~= player
    end,
    on_use = function(self, room, effect)
        local player = effect.from
        local target = effect.tos[1]
        local card = effect.cards[1]
        room:setPlayerMark(player, "lsp_jizha_id-turn", target.id)
        room:setPlayerMark(player, "lsp_jizha-turn", 0)
        local choice = U.askForChooseCardNames(room, player, room:getBanner(lsp_jizha.name), 1, 1, lsp_jizha.name,
            "讥诈：你可以声明一种牌名", room:getBanner(lsp_jizha.name), true)
        if #choice == 0 then return end
        player:addToPile("$lsp_jizha", card, false, lsp_jizha.name, player)
        local id = Fk:getCardById(card)
        local chs = { "是", "否" }
        local chc = room:askToChoice(target,
            { choices = chs, skill_name = lsp_jizha.name, prompt = "其扣置的牌是否为" .. Fk:cloneCard(choice[1]):toLogString() })
        if (chc == "是" and Fk:cloneCard(choice[1]).name == id.name) or (chc == "否" and Fk:cloneCard(choice[1]).name ~= id.name) then
            if id.type ~= Card.TypeEquip then
                room:useVirtualCard(id.name, player:getPile("$lsp_jizha"), target, player, lsp_jizha.name, true)
            end
            if id.type == Card.TypeEquip then
                room:useCard({
                    from = target,
                    tos = { player },
                    card = id,
                    skillName = lsp_jizha.name,
                })
            end
        else
            if Fk:cloneCard(choice[1]).type ~= Card.TypeEquip then
                room:useVirtualCard(Fk:cloneCard(choice[1]).name, player:getPile("$lsp_jizha"), player,
                    target, lsp_jizha.name, true)
            end
            if Fk:cloneCard(choice[1]).type == Card.TypeEquip then
                room:useVirtualCard(Fk:cloneCard(choice[1]).name, player:getPile("$lsp_jizha"), player,
                    target, lsp_jizha.name, true)
            end
        end
    end,
})

lsp_jizha:addEffect(fk.CardUseFinished, {
    anim_type = "drawcard",
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(lsp_jizha.name) and
            (data.card:isCommonTrick() or data.card.type == Card.TypeBasic) and
            #data.tos == 1 and player:getMark("lsp_jizha-turn") == 0 and
            table.contains(data.card.skillNames, lsp_jizha.name) --通过技能使用牌
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local use = room:askToUseVirtualCard(player, {
            name = data.card.name,
            skill_name = lsp_jizha.name,
            prompt = "#lsp_jizha-use::" .. data.tos[1].id .. ":" .. data.card.name,
            cancelable = true,
            extra_data = {
                bypass_times = true,
                extraUse = true,
                exclusive_targets = { player:getMark("lsp_jizha_id-turn") },
            },
            skip = true,
        })
        if use then
            event:setCostData(self, { extra_data = use })
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:addPlayerMark(player, "lsp_jizha-turn")
        local use = event:getCostData(self).extra_data
        room:addTableMark(player, lsp_jizha.name, data.card.trueName)
        room:useCard(use)
    end,
})



lsp_jizha:addAcquireEffect(function(self, player, is_start)
    local room = player.room
    if not room:getBanner(lsp_jizha.name) then
        local all_names = {}
        for _, name in ipairs(Fk:getAllCardNames("bte")) do
            if not Fk:cloneCard(name).is_passive and Fk:cloneCard(name).trueName ~= "jink" and Fk:cloneCard(name).trueName ~= "collateral" then
                table.insert(all_names, name)
            end
        end
        room:setBanner(lsp_jizha.name, all_names)
    end
end)
return lsp_jizha
